package com.houfukude.Utils;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.net.ftp.FTPFile;

import com.houfukude.Activity.MainActivity;
import com.houfukude.Activity.NewNoteActivity;
import com.houfukude.Activity.testActivity;
import com.houfukude.NoteList.ItemView;
import com.houfukude.NoteList.NoteListAdapter;
import com.houfukude.NoteList.ItemValue;
import com.houfukude.xtestmgr.R;

import com.houfukude.Utils.FTP_Client;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class SetFragmentView {
	/**
	 * fragment_note_list的界面view设置
	 * 
	 * @param rootView
	 * @param context
	 */
	public static void setNoteListView(View rootView, final Activity activity) {
		ListView lv = (ListView) rootView.findViewById(R.id.note_list);
		List<ItemValue> list = new ArrayList<ItemValue>();
		for (int i = 0; i < 100; i++) {
			ItemValue item_value = new ItemValue();
			item_value.setDay("04月15日");
			item_value.setTime("14:0" + i);
			item_value.setTitle("记录" + i);
			item_value.setDescription("test" + i);
			item_value.setLink("ZK1 第" + i + "层");
			item_value.setExt1(i % 2);
			item_value.setExt2(i % 3);
			item_value.setExt3(i % 5);
			list.add(item_value);
		}
		NoteListAdapter notelistAdapter = new NoteListAdapter(list, activity);

		lv.setAdapter(notelistAdapter);

		OnItemClickListener listener = new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ItemValue value = (ItemValue) view.getTag();
				Toast.makeText(
						activity,
						"position:" + position + " title :"
								+ value.getTitle(),
						Toast.LENGTH_SHORT).show();
				Intent intent = new Intent();
				intent.setClass(activity, NewNoteActivity.class);
				activity.startActivityForResult(intent, 0);
			}
		};
		lv.setOnItemClickListener(listener);
	}

	public static void setFtpClientView(View rootView,final Activity activity) {
		ScrollView download_sv = (ScrollView)rootView.findViewById(R.id.download_sv);
		((MainActivity)activity).ftp_layout = (LinearLayout) download_sv.findViewById(R.id.download_list);
		((MainActivity)activity).ftp_Client = new FTP_Client();
		//ftp_Client.setHost("ftp.netscape.com");
		//ftp_Client.setPort(21);
		
		// ((MainActivity)activity).ftp_layout.removeAllViews();
		// new Thread(new Runnable() {
		// @Override
		// public void run() {
		// ((MainActivity)activity).ftp_Client.Initalize(null);
		// ((MainActivity)activity).list =
		// ((MainActivity)activity).ftp_Client.getFiles();
		// ((MainActivity)activity).handler.sendEmptyMessage(V.what.FTP_Initalize);
		// }
		// }).start();
		
	}
	

//	@SuppressLint("SetJavaScriptEnabled")
//	public static void setWebView(View rootView) {
//		WebView webView = (WebView) rootView.findViewById(R.id.webView);
//		// or new // WebView(getActivity());
//		webView.getSettings().setJavaScriptEnabled(true);
//
//		// String encoding = "utf-8";
//		// String historyUrl = null;
//		// String baseUrl = "ftp://192.168.43.1:2221/";
//		// String mimeType = "text/html";
//		// String data = "<h2>Pie</h2>";
//		// webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding,
//		// historyUrl);
//		// http://www.houfukude.tk/wap/
//		webView.loadUrl("http://www.houfukude.tk/wap/");
//		webView.setWebViewClient(new WebViewClient() {
//			// 重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
//			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				view.loadUrl(url);
//				return true;
//			}
//		});
//	}
}
